package com.hzit.loan.task.job;

/**
 * 支付宝建议，凌晨0点以后下载。
 */
public class AliapyReonTaskJob {



    //执行对账
    public void  eucuteRecon(){

        //1.获取对账文件
//        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", APP_ID, APP_PRIVATE_KEY, "json", CHARSET, ALIPAY_PUBLIC_KEY, "RSA2");//获得初始化的AlipayClient
//        AlipayDataDataserviceBillDownloadurlQueryRequest request = new AlipayDataDataserviceBillDownloadurlQueryRequest();//创建API对应的request类
//        request.setBizContent("{" +
//                "    \"bill_type\":\"trade\"," +
//                "    \"bill_date\":\"2016-04-05\"}"); //设置业务参数
//        AlipayDataDataserviceBillDownloadurlQueryResponse response = alipayClient.execute(request);//通过alipayClient调用API，获得对应的response类
//        String urlStr = response.getbody();
//        //根据response中的结果继续业务逻辑处理
//
//    //将接口返回的对账单下载地址传入urlStr
////        String urlStr = "http://dwbillcenter.alipay.com/downloadBillFile.resource?bizType=X&userId=X&fileType=X&bizDates=X&downloadFileName=X&fileId=X";
//    //指定希望保存的文件路径
//            String filePath = "d:/Users/fund_bill_20160405.zip";
//        URL url = null;
//        HttpURLConnection httpUrlConnection = null;
//        InputStream fis = null;
//        FileOutputStream fos = null;
//        try {
//            url = new URL(urlStr);
//            httpUrlConnection = (HttpURLConnection) url.openConnection();
//            httpUrlConnection.setConnectTimeout(5 * 1000);
//            httpUrlConnection.setDoInput(true);
//            httpUrlConnection.setDoOutput(true);
//            httpUrlConnection.setUseCaches(false);
//            httpUrlConnection.setRequestMethod("GET");
//            httpUrlConnection.setRequestProperty("Charsert", "UTF-8");
//            httpUrlConnection.connect();
//            fis = httpUrlConnection.getInputStream();
//            byte[] temp = new byte[1024];
//            int b;
//            fos = new FileOutputStream(new File(filePath));
//            while ((b = fis.read(temp)) != -1) {
//                fos.write(temp, 0, b);
//                fos.flush();
//            }
//        } catch (MalformedURLException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        } finally {
//            try {
//                if(fis!=null) fis.close();
//                if(fos!=null) fos.close();
//                if(httpUrlConnection!=null) httpUrlConnection.disconnect();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }

        //吧对账文件路口放插入对账文件路径表

        //2.解压，gzp

        // 解析对账文件 openCsV解析

        for (int i = 0;i<100;i++){

            String amt = "100";
            String tradeTime = "2020-12-14 09:40:51";
            String reconTradeNo = "899898979879879";
            String outTradeNo = "1334773020404879360";
        }

        //入库：存入临时表 recon_temp



        //3.找出对账文件和流水表中差异数据




        //维度一：用对账文件中的数据去配交易表里面的数据
        // select * from recon_temp = 'alipay' limtt 0,10000。 放入redis

//
//        for (int i =0;i<1000; i++){
//
//            //线程池：select * from tb_pay_serial where bank_resp_no = '';
//
//            //如果不存在是，丢单
//
//            //在对比金额，不匹配
//
//        }

        //维度二：用流水表中的数据去配对账文件中的数据
        // select * from tb_pay_serial = 'alipay' limtt 0,10000， redis

//        for (int i =0;i<1000; i++){
//
////            线程池select * from tb_pay_serial where outTradeNo = '';
//
//            //如果不存在是，丢单
//
//            //在对比金额，不匹配
//
//        }




        //对比redis中的集合，

        //清空临时表

        //4. 吧差异数据存入对账差异表


    }
}
